/* 所有地图图层
 * @ 劳兆城
 * @ 2017-08-08 */

import { Static, httpUrl, mapHttpUrl20462, mapHttpUrl20463, ERR_OK } from './config'
import { ajaxGet, ajaxPost } from './axios'
import { createHtml, getWidth } from 'common/js/dom'
import { typhoonStrongLegend, typhoonForecastLegend } from 'common/js/module'
import { timeFilter } from 'common/js/util'

let globalConfig = {
  mapIp: 'http://192.168.1.23:8083/mapdata'//测试
}

// 实例一个map
export function createMap (el, layers) {
	var select = new ol.interaction.Select({
        wrapX: false
      })

	var modify = new ol.interaction.Modify({
	   	features: select.getFeatures()
	})
	return new ol.Map({
		interactions: ol.interaction.defaults().extend([select, modify]),
		target: el,
		layers: layers,
		view: new ol.View({
			center: [113.0445, 23.0907],
			zoom: 11,
			maxZoom: 19,
			minZoom: 5,
			projection: 'EPSG:4326'
			// extent: [109.6820068359375, 20.264282226562504, 116.8670654296875, 25.3729248046875]
		}),
		controls: ol.control.defaults({
			attribution: false
		})
	})
}

// 实例一个 圆形 画图工具
export function createMapCircleDraw (Map, Layer) {
	return {
		init: function () {
			this.activeType = null
			this.Circle.setActive(false)
			Map.addInteraction(this.Circle)
		},
		Circle: new ol.interaction.Draw({
			source: Layer.getSource(),
			type: /** @type {ol.geom.GeometryType} */ ('Circle')
		}),
		getActive: function () {
			return this.activeType ? this[this.activeType].getActive() : false
		},
		setActive: function (active) {
			var type = 'Circle'
			if (active) {
				this.activeType && this[this.activeType].setActive(false)
				this[type].setActive(true)
				this.activeType = type
			} else {
				this.activeType && this[this.activeType].setActive(false)
				this.activeType = null
			}
		}
	}
}

// 获取地图 Layer
export function getLayer (layerName, option) {
	let fn
	switch (layerName) {
		// 基础图层
		case 'baseLayer':
			fn = baseLayer()
			break
		case 'heightLayer':
			fn = heightLayer()
			break
		case 'GdPanoramaLayer':
			fn = GdPanoramaLayer()
			break
		case 'FsPanoramaLayer':
			fn = FsPanoramaLayer()
			break
		case 'FsNhLayer':
			fn = FsNhLayer()
			break
		case 'notionLayer':
			fn = notionLayer()
			break
		case 'warnLineLayer':
			fn = warnLineLayer()
			break

			// 实时数据
			// 气象
		case 'rainLayer':
			fn = rainLayer()
			break
		case 'windLayer':
			fn = windLayer()
			break
		case 'temperatureLayer':
			fn = temperatureLayer()
			break
		case 'weatherWarningLayer':
			fn = weatherWarningLayer()
			break
		case 'typhoonLayer':
			fn = typhoonLayer()
			break
		case 'cloudLayer':
			fn = cloudLayer()
			break
		case 'radarLayer':
			fn = radarLayer()
			break

			// 佛山河流
		case 'chanchenLayer':
			fn = chanchenLayer(option.list)
			break
		case 'nanhaiLayer':
			fn = nanhaiLayer(option.list)
			break
		case 'shundeLayer':
			fn = shundeLayer(option.list)
			break
		case 'sanshuiLayer':
			fn = sanshuiLayer(option.list)
			break
		case 'gaomingLayer':
			fn = gaomingLayer(option.list)
			break

			// 水利
		case 'reservoirLayer':
			fn = reservoirLayer()
			break
		case 'gateLayer':
			fn = gateLayer()
			break
		case 'pumpLayer':
			fn = pumpLayer()
			break
		case 'waterloggingLayer':
			fn = waterloggingLayer()
			break
		case 'waterLevelLayer':
			fn = waterLevelLayer()
			break
		case 'tideGaugeLayer':
			fn = tideGaugeLayer()
			break

			// 监管对象
			// 危险品
		case 'constructionSiteLayer':
			fn = constructionSiteLayer()
			break
		case 'dangerousGoodsLayer':
			fn = dangerousGoodsLayer()
			break

			// 基础数据
			// 水利
		case 'GDwaterNetLayer':
			fn = GDwaterNetLayer()
			break
		case 'HNwaterNetLayer':
			fn = HNwaterNetLayer()
			break
		case 'singleWaterNetLayer':
			fn = singleWaterNetLayer()
			break
		case 'drainPortLayer':
			fn = drainPortLayer()
			break
		case 'buildingLayer':
			fn = buildingLayer()
			break
		case 'banksLayer':
			fn = banksLayer()
			break
		case 'criticalsLayer':
			fn = criticalsLayer()
			break
		case 'waterGateLayer':
			fn = waterGateLayer()
			break
		case 'drainStationLayer':
			fn = drainStationLayer()
			break
		case 'hydrologyLayer':
			fn = hydrologyLayer()
			break

			// 供排水
		case 'blackPointLayer':
			fn = blackPointLayer()
			break
		case 'sunkenTunnelLayer':
			fn = sunkenTunnelLayer()
			break
		case 'supplyPipeLayer':
			fn = supplyPipeLayer()
			break
		case 'waterFactoryLayer':
			fn = waterFactoryLayer()
			break
		case 'supplyDeviceLayer':
			fn = supplyDeviceLayer()
			break
		case 'drainPipeLayer':
			fn = drainPipeLayer()
			break
		case 'dirtyFactoryLayer':
			fn = dirtyFactoryLayer()
			break
		case 'drainDeviceLayer':
			fn = drainDeviceLayer()
			break

			// 三防
		case 'rusticateLayer':
			fn = rusticateLayer()
			break
		case 'roadNetLayer':
			fn = roadNetLayer()
			break
		case 'hazardLayer':
			fn = hazardLayer()
			break

			// 重点场所
		case 'hospitalLayer':
			fn = hospitalLayer()
			break
		case 'schoolLayer':
			fn = schoolLayer()
			break
		case 'bankLayer':
			fn = bankLayer()
			break
		case 'busStationLayer':
			fn = busStationLayer()
			break
		case 'shopLayer':
			fn = shopLayer()
			break

			// 三防数据
			// 预警数据
		case 'waterLevelWillLayer':
			fn = waterLevelWillLayer()
			break
		case 'forecastTemperatureLayer':
			fn = forecastTemperatureLayer()
			break
		case 'forecastRainfallLayer':
			fn = forecastRainfallLayer()
			break
		case 'detectTyphoonLayer':
			fn = detectTyphoonLayer()
			break
		case 'emergencyWarnLayer':
			fn = emergencyWarnLayer()
			break

			// 三防人员
		case 'emergencySquadLayer':
			fn = emergencySquadLayer()
			break
		case 'rescueTeamLayer':
			fn = rescueTeamLayer()
			break
		case 'massHeatLayer':
			fn = massHeatLayer()
			break
		case 'liabilityPersonLayer':
			fn = liabilityPersonLayer()
			break
		case 'defenseExpertLayer':
			fn = defenseExpertLayer()
			break

			// 三防场所
		case 'refugeLayer':
			fn = refugeLayer()
			break
		case 'emergencyLayer':
			fn = emergencyLayer()
			break

			// 三防实时监控
		case 'weatherVideoLayer':
			fn = weatherVideoLayer()
			break
		case 'policVideoLayer':
			fn = policVideoLayer()
			break
		case 'westRiverVideoLayer':
			fn = westRiverVideoLayer()
			break
		case 'pollutionVideoLayer':
			fn = pollutionVideoLayer()
			break
		case 'waterProjectVideoLayer':
			fn = waterProjectVideoLayer()
			break
		case 'refugeVideoLayer':
			fn = refugeVideoLayer()
			break

			// 空间查询画图工具
		case 'searchSpaceDrawLayer':
			fn = searchSpaceDrawLayer()
			break
			// 搜索 建筑 结果
		case 'searchBuildLayer':
			fn = searchBuildLayer(option.searchContent)
			break
			// 搜索 河流 结果
		case 'searchRiverLayer':
			fn = searchRiverLayer(option.searchContent)
			break
			// 空间查询
		case 'searchSpaceLayer':
			fn = searchSpaceLayer(option.center, option.local)
			break
			// 空间查询 分类 统计框
		case 'searchSpaceTypeLayer':
			fn = searchSpaceTypeLayer()
			break
			// 搜索和空间查询点击列表
		case 'searchClickLayer':
			fn = searchClickLayer()
			break
			// 河长制搜索河流
		case 'searchRiverLayer1':
			fn = searchRiverLayer1(option.name)
      break
    case 'pollutionLayer':
      fn = pollutionLayer()
      break
    case 'videoLayer':
      fn = videoLayer()
      break
    case 'waterQualityLayer':
      fn = waterQualityLayer()
      break
    case 'yuliangLayer':
      fn = yuliangLayer()
      break
    default:
      fn = nodataLayer(layerName)
      break
	}

	return fn || Promise.resolve({})
}

export function getLayer2 (item, option) {
  let fn
  let layerName = item.layer
	switch (layerName) {
		case 'searchRiverLayer':
			fn = searchRiverLayer(option.searchContent)
			break
	}
	return fn || Promise.resolve({})
}

// 假数据layer
function nodataLayer (layerName) {
  let url = `${globalConfig.mapIp}/bis/getrandom`
  return ajaxGet(url).then(res => {
    let features = createNodataFeatures(res.result.result, res.result.color)
    let layer = createFeaturesLayer(layerName, features)
    return Promise.resolve({
      code: res.code,
      layer: layer
    })
  })
}

function createNodataFeatures (data = [], color, scale = 0.5) {
  let features = []
	for (let i = 0; i < data.length; i++) {
		if (data[i].geometry.coordinates && data[i].geometry.coordinates.length > 0) {
			let feature = new ol.Feature(new ol.geom.Point([data[i].geometry.coordinates[0], data[i].geometry.coordinates[1]]))
			feature.set('style', new ol.style.Style({
				image: new ol.style.Circle({
          radius: 10,
					fill: new ol.style.Fill({
            color: color
          })
				})
			}))
			features.push(feature)
		}
	}
	return features
}

// 创建Features
function createFeatures (LNT, LAT, data = [], img, scale = 0.5) {
	let features = []
	for (let i = 0; i < data.length; i++) {
		if (+data[i][LNT] && +data[i][LAT]) {
			let feature = new ol.Feature(new ol.geom.Point([data[i][LNT], data[i][LAT]]))
			feature.set('style', new ol.style.Style({
				image: new ol.style.Icon({
					src: img,
					scale: scale
				})
			}))
			feature.set('content', data[i])
			features.push(feature)
		}
	}
	return features
}

function createHzzFeatures (data = [], img, type = 0, scale = 0.5) {
  let features = []
	for (let i = 0; i < data.length; i++) {
		if (data[i].geometry.coordinates && data[i].geometry.coordinates.length > 0) {
			let feature = new ol.Feature(new ol.geom.Point([data[i].geometry.coordinates[0], data[i].geometry.coordinates[1]]))
			feature.set('style', new ol.style.Style({
				image: new ol.style.Icon({
					src: img,
					scale: scale
				})
      }))
      if (type === 0) {
        feature.set('content', data[i].ch_propertite)
      } else if (type === 1) {
        feature.set('content', data[i].files)
      } else if (type === 2) {
        feature.set('content', {id: data[i]._id})
      }
			features.push(feature)
		}
	}
	return features
}

function createHzzLine (arr = [], name, color) {
  let data = []
  arr.map(item => {
    data.push(createGeo(item.geometry.type, item.geometry.coordinates, item.ch_propertite))
  })
  let geoJson = {
    features: data,
    type: 'FeatureCollection'
  }
  let layer = new ol.layer.Vector({
    source: new ol.source.Vector({
      features: (new ol.format.GeoJSON()).readFeatures(geoJson, {
        dataProjection: 'EPSG:4326',
        featureProjection: 'EPSG:4326'
      })
    }),
    style: function (feature, resolution) {
      return new ol.style.Style({
        stroke: new ol.style.Stroke({
          color: color,
          width: 3
        })
      })
    },
    name: name
  })
  return layer
}

function createHzzMian (arr = [], name, color = []) {
  let data = []
  arr.map(item => {
    data.push(createGeo(item.geometry.type, item.geometry.coordinates, item.ch_propertite))
  })
  let geoJson = {
    features: data,
    type: 'FeatureCollection'
  }
  let layer = new ol.layer.Vector({
    source: new ol.source.Vector({
      features: (new ol.format.GeoJSON()).readFeatures(geoJson, {
        dataProjection: 'EPSG:4326',
        featureProjection: 'EPSG:4326'
      })
    }),
    style: function (feature, resolution) {
      return new ol.style.Style({
        stroke: new ol.style.Stroke({
          color: color[0],
          width: 3
        }),
        fill: new ol.style.Fill({
          color: color[1]
        })
      })
    },
    name: name
  })
  return layer
}

// 创建FeaturesLayer
function createFeaturesLayer (name, features, zIndex = 1) {
	return new ol.layer.Vector({
		style: function (feature) {
			return feature.get('style')
		},
		source: new ol.source.Vector({
			features: features
		}),
		name: name,
		zIndex: zIndex
	})
}

// 创建OverLayer
function createdOverLayer (el, lng, lat, offset = [0, -5]) {
	return new ol.Overlay({
		element: el,
		position: [lng, lat],
		offset: offset,
		stopEvent: false
	})
}

// 创建KMLLayer
function createKMLLayer (kmlUrl, name) {
	return new ol.layer.Vector({
		source: new ol.source.Vector({
			url: kmlUrl,
			format: new ol.format.KML({
				showPointNames: false
			})
		}),
		name: name
	})
}

// 创建GeoJsonLayer
function createGeoJsonLayer (geoJsonUrl, name) {
	return new ol.layer.Vector({
		source: new ol.source.Vector({
			url: geoJsonUrl,
			format: new ol.format.GeoJSON(),
			wrapX: false
		}),
		style: function (feature, resolution) {
			return geoJsonStyles[feature.getProperties()['style']]
		},
		name: name
	})
}

// 创建GeoJson
function createGeo (type, coordinates, item) {
	return {
		geometry: {
			type: type,
			coordinates: coordinates
		},
		properties: {
			...item
		},
		type: 'Feature'
	}
}

function pollutionLayer () {
  let url = `${globalConfig.mapIp}/bis/getwryuan`

	return ajaxGet(url, {})
		.then(res => {
      res.result.result.map(item => {
        item.ch_propertite.report_no = item.report_no
      })
			let features = createHzzFeatures(res.result.result, `${Static}img/mapIcon/radar.png`)
			let layer = createFeaturesLayer('pollutionLayer', features)
			return Promise.resolve({
				code: res.code,
				layer: layer
			})
		})
		.catch(res => {
			return Promise.resolve(res)
		})
}

function yuliangLayer () {
  let url = `${globalConfig.mapIp}/bis/getrain`
  return ajaxGet(url, {})
		.then(res => {
			let features = createHzzFeatures(res.result, `${Static}img/mapIcon/drainStation.png`)
			let layer = createFeaturesLayer('yuliangLayer', features)
			return Promise.resolve({
				code: res.code,
				layer: layer
			})
		})
		.catch(res => {
			return Promise.resolve(res)
		})
}

function waterQualityLayer () {
  let url = `${globalConfig.mapIp}/bis/getwqaddress`

	return ajaxGet(url, {})
		.then(res => {
			let features = createHzzFeatures(res.result, `${Static}img/mapIcon/waterQuality.png`, 2)
			let layer = createFeaturesLayer('waterQualityLayer', features)
			return Promise.resolve({
				code: res.code,
				layer: layer
			})
		})
		.catch(res => {
			return Promise.resolve(res)
		})
}

function videoLayer () {
  let url = `${globalConfig.mapIp}/bis/getrivideo`

	return ajaxGet(url, {})
		.then(res => {
			let features = createHzzFeatures(res.result.result, `${Static}img/mapIcon/waterGate.png`, 1)
			let layer = createFeaturesLayer('videoLayer', features)
			return Promise.resolve({
				code: res.code,
				layer: layer
			})
		})
		.catch(res => {
			return Promise.resolve(res)
		})
}

// 创建ArcGIS
export function createdArcGISSource (sourceUrl) {
	return new ol.source.TileArcGISRest({
		url: sourceUrl
	})
}

// 创建Kml
export function createdKmlSource (kml) {
	return new ol.source.Vector({
		features: (new ol.format.KML({
			extractStyles: false
		})).readFeatures(kml, {
			dataProjection: 'EPSG:4326',
			featureProjection: 'EPSG:4326'
		})
	})
}

/* 基础图层 */
// 普通地图 Layer
function baseLayer () {
	return new ol.layer.Tile({
		source: new ol.source.TileArcGISRest({
			url: `${mapHttpUrl20462}arcgis/rest/services/data_visualization/basemap_backgroud_normal/MapServer`
		}),
		visible: false
	})
}

// 地形图 Layer
function heightLayer () {
	return new ol.layer.Tile({
		source: new ol.source.XYZ({
			url: `${mapHttpUrl20463}static/map_tile/gaocheng_guangdong_google/tiles/{z}/{y}/{x}.png`
		}),
		visible: false
	})
}

// 广东卫星图 Layer
function GdPanoramaLayer () {
	return new ol.layer.Tile({
		source: new ol.source.XYZ({
			url: `${mapHttpUrl20463}static/map_tile/satellite_guangdong_tiandi/tiles/{z}/{y}/{x}.png`,
			minZoom: 0,
			maxZoom: 18
		}),
		visible: false
	})
}

// 佛山卫星图 Layer
function FsPanoramaLayer () {
	return new ol.layer.Tile({
		source: new ol.source.XYZ({
			url: `${mapHttpUrl20463}static/map_tile/satellite_foshan_tiandi/tiles/{z}/{y}/{x}.png`,
			minZoom: 0,
			maxZoom: 18
		}),
		visible: false
	})
}

// 佛山南海 Layer
function FsNhLayer () {
	return new ol.layer.Tile({
		source: new ol.source.TileArcGISRest({
			url: `${mapHttpUrl20462}arcgis/rest/services/data_visualization/basemap_foshan_nanhai/MapServer`
		}),
		visible: false
	})
}

// 镇街名 Layer
function notionLayer () {
	return new ol.layer.Tile({
		source: new ol.source.TileArcGISRest({
			url: `${mapHttpUrl20462}arcgis/rest/services/data_visualization/notation/MapServer`
		})
	})
}

// 警戒线 Layer
function warnLineLayer () {
	let arr1 = [
			[127, 34],
			[127, 22],
			[119, 18],
			[119, 11],
			[113, 4.5],
			[105, 0]
		],
		arr2 = [
			[132, 34],
			[132, 15],
			[120, 0],
			[105, 0]
		]

	var feature1 = new ol.Feature({
		geometry: new ol.geom.LineString(arr1)
	})
	feature1.setStyle(new ol.style.Style({
		stroke: new ol.style.Stroke({
			color: 'red',
			width: 1
		}),
		text: new ol.style.Text({
			text: '24小时警戒线',
			font: '14px 微软雅黑',
			fill: new ol.style.Fill({
				color: 'white'
			}),
			stroke: new ol.style.Stroke({
				color: 'black',
				width: 2
			})
		})
	}))
	var feature2 = new ol.Feature({
		geometry: new ol.geom.LineString(arr2)
	})
	feature2.setStyle(new ol.style.Style({
		stroke: new ol.style.Stroke({
			color: 'green',
			width: 2,
			lineDash: [9]
		}),
		text: new ol.style.Text({
			text: '48小时警戒线',
			font: '14px 微软雅黑',
			fill: new ol.style.Fill({
				color: 'white'
			}),
			stroke: new ol.style.Stroke({
				color: 'black',
				width: 2
			})
		})
	}))

	return new ol.layer.Vector({
		source: new ol.source.Vector({
			features: [feature1, feature2]
		}),
		name: 'warnLineLayer'
	})
}

/* 实时数据 */
// 雨 Layer
function rainLayer () {
	let url = `${httpUrl}fullservice/http/mapService`

	return ajaxGet(url, {
			type: 'rain-1-hour'
		})
		.then(res => {
			let layer = new ol.layer.Tile({
				source: new ol.source.TileArcGISRest({
					url: res.result[0].serviceResult
				})
			})
			return Promise.resolve({
				code: res.code,
				layer: layer,
				result: res.result
			})
		})
		.catch(res => {
			return Promise.resolve(res)
		})
}

// 风力风向 Layer
function windLayer () {
	let url = `${httpUrl}fullservice/http/mapService`

	return ajaxGet(url, {
			type: 'wind-1-hour'
		})
		.then(res => {
			let layer = new ol.layer.Tile({
				source: new ol.source.TileArcGISRest({
					url: res.result[0].serviceResult
				})
			})
			return Promise.resolve({
				code: res.code,
				layer: layer,
				result: res.result
			})
		})
		.catch(res => {
			return Promise.resolve(res)
		})
}

// 温度 Layer
function temperatureLayer () {
	let url = `${httpUrl}fullservice/http/mapService`

	return ajaxGet(url, {
			type: 'temp-min'
		})
		.then(res => {
			let layer = new ol.layer.Tile({
				source: new ol.source.TileArcGISRest({
					url: res.result[0].serviceResult
				})
			})
			return Promise.resolve({
				code: res.code,
				layer: layer,
				result: res.result
			})
		})
		.catch(res => {
			return Promise.resolve(res)
		})
}

// 气象预警 Layer
function weatherWarningLayer () {
	let url = `${httpUrl}fullservice/http/metorWarn`

	return ajaxGet(url, {})
		.then(res => {
			let overLayerArr = []

			if (res.result.length) {
				res.result.map(item => {
					let el = createHtml('div')
					el.className = 'weather-warning aPicture-map-infoOverLayer'

					let ul = createHtml('ul')
					ul.className = 'aPicture-map-infoOverLayer-warpper'

					let htmlStr = ''
					item.content.map(items => {
						htmlStr += `<li class="weather-warning-li">
										<img src="${Static}img/mapIcon/alerticons/${items.level}.png" />
										<span>${items.description}</span>
									</li>`
					})
					ul.innerHTML = htmlStr

					el.append(ul)

					let div = createHtml('div')
					div.className = 'boxTail'
					div.innerHTML = `<img src="${Static}img/aPicture/boxTail.png" />`

					el.append(div)

					let overLayer = createdOverLayer(el, item.lng, item.lat)
					overLayerArr.push(overLayer)
				})
			} else {
				let el = createHtml('div')
				el.className = 'weather-warning aPicture-map-infoOverLayer'

				let ul = createHtml('ul')
				ul.className = 'aPicture-map-infoOverLayer-warpper'

				let htmlStr = `<li class="weather-warning-li">
									<img src="${Static}img/mapIcon/alerticons/no-alerm.gif" />
									<span>无预警</span>
								</li>`
				ul.innerHTML = htmlStr

				el.append(ul)

				let div = createHtml('div')
				div.className = 'boxTail'
				div.innerHTML = `<img src="${Static}img/aPicture/boxTail.png" />`

				el.append(div)

				let overLayer = createdOverLayer(el, 113.0445, 23.0907)
				overLayerArr.push(overLayer)
			}

			return Promise.resolve({
				code: res.code,
				overLayerArr: overLayerArr
			})
		})
		.catch(res => {
			return Promise.resolve(res)
		})
}

//
function searchRiverLayer1 (name) {
	let url = '/riverchief/waterenvir/bsiriver/list'
	let data = {
	                searchValue: {
	                    river_name: name + '|#|like'
	                },
	                fieldName: ['coordinates', '_id', 'river_no']
	            }
	return ajaxPost(url, data).then(res => {
		console.log(res)
		let arr = []
        res.result.result.map((item) => {
            if (item.coordinates.length != 0) {
        		arr.push(createGeo('LineString', item.coordinates, item))
        	}
        })
        let geoJson = {
            features: arr,
            type: 'FeatureCollection'
        }
        let layer = new ol.layer.Vector({
            source: new ol.source.Vector({
                features: (new ol.format.GeoJSON()).readFeatures(geoJson, {
                    dataProjection: 'EPSG:4326',
                    featureProjection: 'EPSG:4326'
                })
            }),
            style: function (feature, resolution) {
                return new ol.style.Style({
                    stroke: new ol.style.Stroke({
                        color: '#0099ff',
                        width: 3
                    })
                })
            },
            name: 'searchRiverLayer1'
        })
        return Promise.resolve({
			code: res.code,
			layer: layer
		})
	})
}

// 佛山河流禅城区
function chanchenLayer (params) {
	let url = '/riverchief/waterenvir/bsiriver/list'
	let data = {
	                searchValue: [],
	                fieldName: ['coordinates', '_id', 'river_no', 'river_name']
	            }
	if(Array.isArray(params) && params.length > 0) {
		data.searchValue = params;
	}
	return ajaxPost(url, data).then(res => {
		console.log(res)
		let arr = []
        res.result.result.map((item) => {
            if (item.coordinates.length != 0) {
        		arr.push(createGeo('LineString', item.coordinates, item))
        	}
        })
        let geoJson = {
            features: arr,
            type: 'FeatureCollection'
        }
        let layer = new ol.layer.Vector({
            source: new ol.source.Vector({
                features: (new ol.format.GeoJSON()).readFeatures(geoJson, {
                    dataProjection: 'EPSG:4326',
                    featureProjection: 'EPSG:4326'
                })
            }),
            style: function (feature, resolution) {
                return new ol.style.Style({
                    stroke: new ol.style.Stroke({
                        color: '#0099ff',
                        width: 3
                    })
                })
            },
            name: 'chanchenLayer'
        })
        return Promise.resolve({
			code: res.code,
			layer: layer
		})
	})
}

// 佛山河流三水区
function sanshuiLayer (params) {
	let url = '/riverchief/waterenvir/bsiriver/list'
	let data = {
	                searchValue: [],
	                fieldName: ['coordinates', '_id', 'river_no', 'river_name']
	            }
	if(Array.isArray(params) && params.length > 0) {
		data.searchValue = params;
	}
	return ajaxPost(url, data).then(res => {
		console.log(res)
		let arr = []
        res.result.result.map((item) => {
        	if (item.coordinates.length != 0) {
        		arr.push(createGeo('LineString', item.coordinates, item))
        	}
        })
        let geoJson = {
            features: arr,
            type: 'FeatureCollection'
        }
        let layer = new ol.layer.Vector({
            source: new ol.source.Vector({
                features: (new ol.format.GeoJSON()).readFeatures(geoJson, {
                    dataProjection: 'EPSG:4326',
                    featureProjection: 'EPSG:4326'
                })
            }),
            style: function (feature, resolution) {
                return new ol.style.Style({
                    stroke: new ol.style.Stroke({
                        color: '#0099ff',
                        width: 3
                    })
                })
            },
            name: 'sanshuiLayer'
        })
        return Promise.resolve({
			code: res.code,
			layer: layer
		})
	})
}

// 佛山河流顺德区
function shundeLayer (params) {
	let url = '/riverchief/waterenvir/bsiriver/list'
	let data = {
	                searchValue: [],
	                fieldName: ['coordinates', '_id', 'river_no', 'river_name']
	            }
	if(Array.isArray(params) && params.length > 0) {
		data.searchValue = params;
	}
	return ajaxPost(url, data).then(res => {
		console.log(res)
		let arr = []
        res.result.result.map((item) => {
            if (item.coordinates.length != 0) {
        		arr.push(createGeo('LineString', item.coordinates, item))
        	}
        })
        let geoJson = {
            features: arr,
            type: 'FeatureCollection'
        }
        let layer = new ol.layer.Vector({
            source: new ol.source.Vector({
                features: (new ol.format.GeoJSON()).readFeatures(geoJson, {
                    dataProjection: 'EPSG:4326',
                    featureProjection: 'EPSG:4326'
                })
            }),
            style: function (feature, resolution) {
                return new ol.style.Style({
                    stroke: new ol.style.Stroke({
                        color: '#0099ff',
                        width: 3
                    })
                })
            },
            name: 'shundeLayer'
        })
        return Promise.resolve({
			code: res.code,
			layer: layer
		})
	})
}

// 佛山河流高明区
function gaomingLayer (params) {
	let url = '/riverchief/waterenvir/bsiriver/list'
	let data = {
	                searchValue: [],
	                fieldName: ['coordinates', '_id', 'river_no', 'river_name']
	            }
	if(Array.isArray(params) && params.length > 0) {
		data.searchValue = params;
	}
	return ajaxPost(url, data).then(res => {
		console.log(res)
		let arr = []
        res.result.result.map((item) => {
            if (item.coordinates.length != 0) {
        		arr.push(createGeo('LineString', item.coordinates, item))
        	}
        })
        let geoJson = {
            features: arr,
            type: 'FeatureCollection'
        }
        let layer = new ol.layer.Vector({
            source: new ol.source.Vector({
                features: (new ol.format.GeoJSON()).readFeatures(geoJson, {
                    dataProjection: 'EPSG:4326',
                    featureProjection: 'EPSG:4326'
                })
            }),
            style: function (feature, resolution) {
                return new ol.style.Style({
                    stroke: new ol.style.Stroke({
                        color: '#0099ff',
                        width: 3
                    })
                })
            },
            name: 'gaomingLayer'
        })
        return Promise.resolve({
			code: res.code,
			layer: layer
		})
	})
}

// 佛山河流南海区
function nanhaiLayer (params) {
	let url = '/riverchief/waterenvir/bsiriver/list'
	let data = {
	                searchValue: [],
	                fieldName: ['coordinates', '_id', 'river_no', 'river_name']
	            }
	if(Array.isArray(params) && params.length > 0) {
		data.searchValue = params;
	}
	return ajaxPost(url, data).then(res => {
		console.log(res)
		let arr = []
        res.result.result.map((item) => {
            if (item.coordinates.length != 0) {
        		arr.push(createGeo('LineString', item.coordinates, item))
        	}
        })
        let geoJson = {
            features: arr,
            type: 'FeatureCollection'
        }
        let layer = new ol.layer.Vector({
            source: new ol.source.Vector({
                features: (new ol.format.GeoJSON()).readFeatures(geoJson, {
                    dataProjection: 'EPSG:4326',
                    featureProjection: 'EPSG:4326'
                })
            }),
            style: function (feature, resolution) {
                return new ol.style.Style({
                    stroke: new ol.style.Stroke({
                        color: '#0099ff',
                        width: 3
                    })
                })
            },
            name: 'nanhaiLayer'
        })
        return Promise.resolve({
			code: res.code,
			layer: layer
		})
	})
}

// 创建风圈 tip
function createRingTipOverlay () {
	let el = createHtml('div')
	el.className = 'typhoon-ringTip aPicture-map-infoOverLayer pad-10'

	let infoDiv = createHtml('div')
	infoDiv.className = 'aPicture-map-infoOverLayer-warpper blue'
	el.append(infoDiv)

	let div = createHtml('div')
	div.className = 'boxTail'
	div.innerHTML = `<img src="${Static}img/aPicture/boxTail.png" />`

	el.append(div)

	return createdOverLayer(el, 113.0445, 23.0907)
}

// 创建台风路径 基础信息 tip
function createTyphoonInfoOverlay () {
	let el = createHtml('div')
	el.className = 'typhoon-baseTip aPicture-map-infoOverLayer'

	let infoDiv = createHtml('div')
	infoDiv.className = 'typhoon-baseTip-warpper'
	infoDiv.innerHTML = `
		<div class="typhoon-baseTip-header">台风路径信息</div>
		<div class="typhoon-baseTip-content"></div>
	`

	el.append(infoDiv)

	let div = createHtml('div')
	div.className = 'boxTail'
	div.innerHTML = `<img src="${Static}img/aPicture/boxTail.png" />`

	el.append(div)

	return createdOverLayer(el, 113.0445, 23.0907)
}

// 创建台风路径
export function createTyphoon (info) {
	let option = info.points[0],
		options = info.points

	// 风圈
	let ringColor = {
		radius7_quad: {
			'bg-color': 'rgba(155, 219, 203, 0.4)',
			'border-color': '#24B43D',
			'text': '7级风圈'
		},
		radius10_quad: {
			'bg-color': 'rgba(244, 255, 151, 0.4)',
			'border-color': '#DCD024',
			'text': '10级风圈'
		},
		radius12_quad: {
			'bg-color': 'rgba(247, 179, 178, 0.4)',
			'border-color': '#E72A1D',
			'text': '12级风圈'
		}

	}

	let features = []
	let overLayerArr = []
	let hideClassName = 'mustHideOverLayers-7'

	for (let key in ringColor) {
		let wktformat = new ol.format.WKT()
		let Configs = {
			CIRCLE_CENTER_X: option.longitude,
			CIRCLE_CENTER_Y: option.latitude,
			CIRCLE_R: {
				'SE': +option[key].se / 100 || 0,
				'NE': +option[key].ne / 100 || 0,
				'NW': +option[key].nw / 100 || 0,
				'SW': +option[key].sw / 100 || 0
			}
		}

		if (
			Configs.CIRCLE_R.SE == 0 &&
			Configs.CIRCLE_R.NE == 0 &&
			Configs.CIRCLE_R.NW == 0 &&
			Configs.CIRCLE_R.SW == 0
		) {
			continue
		} else {
			let wkt = 'POLYGON(('
			let wkt0 = '',
				_interval = 1
			for (let i = 0; i < 360 / _interval; i++) {
				let _r = 0
				let _ang = i * _interval
				if (_ang > 0 && _ang <= 90) {
					_r = Configs.CIRCLE_R.NE
				} else if (_ang > 90 && _ang <= 180) {
					_r = Configs.CIRCLE_R.NW
				} else if (_ang > 180 && _ang <= 270) {
					_r = Configs.CIRCLE_R.SW
				} else {
					_r = Configs.CIRCLE_R.SE
				}

				let x = Configs.CIRCLE_CENTER_X + _r * Math.cos(_ang * 3.14 / 180)
				let y = Configs.CIRCLE_CENTER_Y + _r * Math.sin(_ang * 3.14 / 180)

				wkt = wkt + '' + x + ' ' + y + ', '
				if (i === 0) {
					wkt0 = '' + x + ' ' + y + ''
				}
			}
			wkt = wkt + wkt0 + '))'
			let ringFeature = wktformat.readFeature(wkt)
			ringFeature.setStyle(new ol.style.Style({
				fill: new ol.style.Fill({
					color: ringColor[key]['bg-color']
				}),
				stroke: new ol.style.Stroke({
					color: ringColor[key]['border-color'],
					width: 2
				})
			}))
			ringFeature.set('custom_name', 'typhoonRing')
			ringFeature.set('ring_name', ringColor[key]['text'])
			ringFeature.set('ring_length', option[key])
			features.push(ringFeature)
		}
	}

	// 预测路径
	if (option.forecast) {
		option.forecast.map(item => {
			let points = item.points
			let localArr = []

			let ForecastIndex = typhoonForecastLegend.findIndex(items => items.name === item.sets)
			let color = typhoonForecastLegend[ForecastIndex].color
			let pointColor = typhoonForecastLegend[ForecastIndex].pointColor

			localArr.push([option.longitude, option.latitude])

			item.points.map(items => {
				let local = [+items.longitude, +items.latitude]

				localArr.push(local)

				let feature = new ol.Feature(new ol.geom.Point(local))

				feature.setStyle(new ol.style.Style({
					image: new ol.style.Circle({
						fill: new ol.style.Fill({
							color: pointColor
						}),
						stroke: new ol.style.Stroke({
							color: 'black',
							width: 2
						}),
						radius: 5
					}),
					zIndex: 10
				}))

				let obj = {
					tfbh: option.tfbh,
					typhoon_name: info.name,
					sets: item.sets,
					...items
				}

				feature.set('content', obj)
				feature.set('custom_name', 'typhoonPoint')
				feature.set('custom_type', 'typhoonwill')
				features.push(feature)
				let el = createHtml('div')
				el.className = `typhoon-time ${hideClassName} aPicture-map-infoOverLayer pad-10`
				let infoDiv = createHtml('div')
				infoDiv.innerHTML = `${timeFilter(new Date(items.time.replace('T', ' ')), 'dd日HH时')}`
				el.append(infoDiv)

				overLayerArr.push(createdOverLayer(el, local[0], local[1], [35, 10]))
			})

			let feature = new ol.Feature({
				geometry: new ol.geom.LineString(localArr)
			})

			feature.setStyle(new ol.style.Style({
				stroke: new ol.style.Stroke({
					color: color,
					width: 2,
					lineDash: [9]
				})
			}))
			features.push(feature)
		})
	}

	// 台风路径
	let pointsArr = []

	options.map((item, index) => {
		let points = item.points
		let local = [+item.longitude, +item.latitude]

		if (index === options.length - 1) {
			let el = createHtml('div')
			el.className = 'aPicture-map-infoOverLayer pad-10'

			let infoDiv = createHtml('div')
			infoDiv.className = 'aPicture-map-infoOverLayer-warpper blue'
			infoDiv.innerHTML = `${info.tfbh}: <span class="red">${info.name}</span>`
			el.append(infoDiv)

			let div = createHtml('div')
			div.className = 'boxTail'
			div.innerHTML = `<img src="${Static}img/aPicture/boxTail.png" />`

			el.append(div)

			overLayerArr.push(createdOverLayer(el, local[0], local[1]))
		}

		if (index === 0) {
			let el = createHtml('div')
			el.className = `typhoon-time ${hideClassName} aPicture-map-infoOverLayer pad-10`

			let infoDiv = createHtml('div')
			infoDiv.innerHTML = `${timeFilter(new Date(item.time.replace('T', ' ')), 'dd日HH时')}`
			el.append(infoDiv)

			overLayerArr.push(createdOverLayer(el, local[0], local[1], [40, 8]))
		}

		pointsArr.push(local)

		let feature = new ol.Feature(new ol.geom.Point(local))
		let strongIndex = typhoonStrongLegend.findIndex(items => items.name === item.strong)

		feature.setStyle(new ol.style.Style({
			image: new ol.style.Circle({
				fill: new ol.style.Fill({
					color: typhoonStrongLegend[strongIndex].color
				}),
				stroke: new ol.style.Stroke({
					color: 'black',
					width: 2
				}),
				radius: 5
			}),
			zIndex: 10
		}))

		let obj = {
			typhoon_name: info.name,
			...item
		}

		feature.set('content', obj)
		feature.set('custom_name', 'typhoonPoint')
		feature.set('custom_type', 'typhooned')
		features.push(feature)
	})

	let solidFeature = new ol.Feature({
		geometry: new ol.geom.LineString(pointsArr)
	})

	solidFeature.setStyle(new ol.style.Style({
		stroke: new ol.style.Stroke({
			color: 'black',
			width: 3,
			zIndex: 9
		})
	}))
	features.push(solidFeature)

	// 实时台风强度图标
	let el = createHtml('div')
	let strongIndex = typhoonStrongLegend.findIndex(item => item.name === option.strong)
	el.className = 'typhoon-ringCenter'
	let imgPosition = typhoonStrongLegend[strongIndex].imgPosition
	el.style.backgroundPosition = imgPosition

	let overLayer = createdOverLayer(el, option.longitude, option.latitude)

	overLayerArr.push(overLayer)

	let layer = new ol.layer.Vector({
		source: new ol.source.Vector({
			features: features
		}),
		name: 'typhoonLayer'
	})

	return {
		info,
		tfbh: info.tfbh,
		layer,
		overLayerArr,
		hideClassName: 'mustHideOverLayers-7'
	}
}

// 台风路径 Layer
function typhoonLayer () {
	let url = `${httpUrl}fullservice/http/typhoonPath`

	return ajaxGet(url, {})
		.then(res => {
			let layer = null,
				overLayerArr = [],
				allLayer = {},
				hideClassName = 'mustHideOverLayers-7',
				isHaveTyphoon = true

			if (res.result.length) {
				res.result.map(item => {
					let obj = createTyphoon(item)
					layer = obj.layer
					overLayerArr.push(...obj.overLayerArr)
					allLayer[obj.tfbh] = {
						layer,
						overLayerArr,
						info: obj.info
					}
				})
			} else {
				isHaveTyphoon = false
			}

			return Promise.resolve({
				code: res.code,
				allLayer: allLayer,
				ringTip: createRingTipOverlay(),
				baseInfo: createTyphoonInfoOverlay(),
				hideClassName: hideClassName,
				isHaveTyphoon
			})
		})
		.catch(res => {
			return Promise.resolve(res)
		})
}

function createImgExtent (url, extent) {
	return new ol.layer.Image({
		source: new ol.source.ImageStatic({
			url: url,
			imageExtent: extent
		}),
		opacity: 0.8
	})
}

// 云图 Layer
function cloudLayer () {
	let url = `${httpUrl}fullservice/http/metorImage?imageType=cloudImage`

	return ajaxGet(url, {})
		.then(res => {
			let layer = null,
				extent = [50, 0, 145, 60]

			if (res.result.length) {
				layer = createImgExtent(res.result[res.result.length - 1].imageurl, extent)
			}

			return Promise.resolve({
				code: res.code,
				layer,
				info: res.result,
				extent
			})
		})
		.catch(res => {
			return Promise.resolve(res)
		})
}

// 雷达图 Layer
function radarLayer () {
	let url = `${httpUrl}fullservice/http/metorImage?imageType=radarImage`

	return ajaxGet(url, {})
		.then(res => {
			let layer = null,
				extent = [73, 15.5, 135.5, 55.5]

			if (res.result.length) {
				layer = createImgExtent(res.result[res.result.length - 1].imageurl, extent)
			}

			return Promise.resolve({
				code: res.code,
				layer,
				info: res.result,
				extent
			})
		})
		.catch(res => {
			return Promise.resolve(res)
		})
}

// 水库 Layer
function reservoirLayer () {
	let url = `${globalConfig.mapIp}/bis/getshuiku`

	return ajaxGet(url, {})
		.then(res => {
			let features = createHzzFeatures(res.result.result, `${Static}img/mapIcon/reservoir.png`)
			let layer = createFeaturesLayer('reservoirLayer', features)
			let hideClassName = 'mustHideOverLayers-12'
			return Promise.resolve({
				code: res.code,
				layer: layer,
				hideClassName: hideClassName
			})
		})
		.catch(res => {
			return Promise.resolve(res)
		})
}

// 判断水闸、泵站水位趋势
function waterOutertrend (status) {
	let str = status.replace(' ', '')

	let outerImg = ''

	if (str) {
		let imgUrl = ''

		switch (str) {
			case '涨':
				imgUrl = `${Static}img/aPicture/leftReadLegendYellow.png`
				break
			case '平':
				imgUrl = `${Static}img/aPicture/leftReadLegendBlue.png`
				break
			case '落':
				imgUrl = `${Static}img/aPicture/leftReadLegendGreen.png`
				break
			case '正常':
				imgUrl = `${Static}img/aPicture/leftReadLegendBluew.png`
				break
			case '超警戒/汛限':
				imgUrl = `${Static}img/aPicture/leftReadLegendRed.png`
				break
			default:
				break
		}
		outerImg = `<img class="water-level-img" src="${imgUrl}" />`
	}

	return outerImg
}

// 水闸 Layer
function gateLayer () {
	let url = `${globalConfig.mapIp}/bis/getgate`

	return ajaxGet(url, {})
		.then(res => {
			let features = createHzzFeatures(res.result.result, `${Static}img/mapIcon/gate.png`)
			let layer = createFeaturesLayer('gateLayer', features)
			let hideClassName = 'mustHideOverLayers-12'

			return Promise.resolve({
				code: res.code,
				layer: layer,
				hideClassName: hideClassName
			})
		})
		.catch(res => {
			return Promise.resolve(res)
		})
}

// 泵站 Layer
function pumpLayer () {
	let url = `${httpUrl}fullservice/http/waterStationInfo`

	return ajaxGet(url, {
			sttype: '泵站'
		})
		.then(res => {
			let features = createFeatures('stalong', 'stalat', res.result, `${Static}img/mapIcon/pump.png`)
			let layer = createFeaturesLayer('pumpLayer', features)

			let overLayerArr = []
			let hideClassName = 'mustHideOverLayers-12'
			res.result.map(item => {
				let time = item.realtime_data ? item.realtime_data.data_time ? item.realtime_data.data_time : '--' : '--'
				let name = item.staname
				let level_out = item.realtime_data ? item.realtime_data.water_river_out || item.realtime_data.water_level == 0 ? item.realtime_data.water_river_out : '--' : '--'
				let level_in = item.realtime_data ? item.realtime_data.water_river_in || item.realtime_data.water_level == 0 ? item.realtime_data.water_river_in : '--' : '--'
				let status = item.realtime_data ? item.realtime_data.outertrend ? item.realtime_data.outertrend : '' : ''

				let el = createHtml('div')
				el.className = `water-level ${hideClassName} aPicture-map-infoOverLayer`
				el.innerHTML = `<div class="aPicture-map-infoOverLayer-warpper">
									<div class="water-level-time">
										<span class="red">${time}</span>
									</div>
									<div class="water-level-data">
										<span class="blue">${name}</span>
										内江：
										<span class="blue">${level_in}</span> 米;
										外江：
										<span class="blue">${level_out}</span> 米
										${waterOutertrend(status)}
									</div>
								</div>
								<div class="boxTail">
									<img src="${Static}img/aPicture/boxTail.png" />
								</div>`

				let overLayer = createdOverLayer(el, item.stalong, item.stalat)
				overLayerArr.push(overLayer)
			})

			return Promise.resolve({
				code: res.code,
				layer: layer,
				overLayerArr: overLayerArr,
				hideClassName: hideClassName
			})
		})
		.catch(res => {
			return Promise.resolve(res)
		})
}

function waterWarn (index, alert, level) {
	let str = ''
	switch (index) {
		case '4':
			str += 'drop_'
			break
		case '5':
			str += 'rise_'
			break
		case '6':
			str += 'flat_'
			break
	}

	if (level > alert) {
		str += 'surpass.png'
	} else {
		str += 'normal.png'
	}

	return str
}

// 内涝站 Layer
function waterloggingLayer () {
	let url = `${httpUrl}fullservice/http/swStationInfo`

	return ajaxGet(url, {
			sttype: '内涝站'
		})
		.then(res => {
			let features = createFeatures('lng', 'lat', res.result, `${Static}img/mapIcon/waterlogging.png`)
			let layer = createFeaturesLayer('waterloggingLayer', features)

			let overLayerArr = []
			let hideClassName = 'mustHideOverLayers-12'
			res.result.map(item => {
				let time = item.realtime_data ? item.realtime_data.data_time ? item.realtime_data.data_time : '--' : '--'
				let name = item.stn_name
				let level = item.realtime_data ? item.realtime_data.water_level || item.realtime_data.water_level == 0 ? item.realtime_data.water_level : '--' : '--'
				let warn = item.realtime_data ? item.realtime_data.alarm_l1 || item.realtime_data.alarm_l1 === '-' ? item.realtime_data.alarm_l1 : false : false
				let warnImg = ''

				if (warn) {
					warnImg += `<img class="water-level-warnImg" src="${Static}img/aPicture/${waterWarn(item.realtime_data.trend, item.realtime_data.alarm_l1, item.realtime_data.waterlevel)}" />`
				}

				let el = createHtml('div')
				el.className = `water-level ${hideClassName} aPicture-map-infoOverLayer`
				el.innerHTML = `<div class="aPicture-map-infoOverLayer-warpper">
									<div class="water-level-time">
										<span class="red">${time}</span>
									</div>
									<div class="water-level-data">
										<span class="blue">${name}</span>
										水深：
										<span class="blue">${level}</span> 米
										${warnImg}
									</div>
								</div>
								<div class="boxTail">
									<img src="${Static}img/aPicture/boxTail.png" />
								</div>`

				let overLayer = createdOverLayer(el, item.lng, item.lat)
				overLayerArr.push(overLayer)
			})

			return Promise.resolve({
				code: res.code,
				layer: layer,
				overLayerArr: overLayerArr,
				hideClassName: hideClassName
			})
		})
		.catch(res => {
			return Promise.resolve(res)
		})
}

// 水位站 Layer
function waterLevelLayer () {
	let url = `${globalConfig.mapIp}/bis/getshuigongneng`

	return ajaxGet(url)
		.then(res => {
			let layer = createHzzMian(res.result.result, 'waterLevelLayer', ['#00BFFF', 'rgba(0,191,255,0.3)'])

			return Promise.resolve({
				code: res.code,
				layer: layer
			})
		})
		.catch(res => {
			return Promise.resolve(res)
		})
}

// 水文站 Layer
function hydrologyLayer (map) {
	let url = `${httpUrl}fullservice/http/swStationInfo`

	return ajaxGet(url, {
			sttype: '水文站'
		})
		.then(res => {
			let features = createFeatures('lng', 'lat', res.result, `${Static}img/mapIcon/hydrology.png`)

			let layer = createFeaturesLayer('hydrologyLayer', features)

			let overLayerArr = []
			res.result.map(item => {
				let time = item.realtime_data ? item.realtime_data.data_time ? item.realtime_data.data_time : '--' : '--'
				let name = item.stn_name
				let level = item.realtime_data ? item.realtime_data.water_level || item.realtime_data.water_level == 0 ? item.realtime_data.water_level : '--' : '--'
				let warn = item.realtime_data ? item.realtime_data.alarm_l1 || item.realtime_data.alarm_l1 === '-' ? item.realtime_data.alarm_l1 : false : false
				let warnImg = ''

				if (warn) {
					warnImg += `<img class="water-level-warnImg" src="${Static}img/aPicture/${waterWarn(item.realtime_data.trend, item.realtime_data.alarm_l1, item.realtime_data.waterlevel)}" />`
				}

				let el = createHtml('div')
				el.className = 'water-level aPicture-map-infoOverLayer'
				el.innerHTML = `<div class="aPicture-map-infoOverLayer-warpper">
									<div class="water-level-time">
										<span class="red">${time}</span>
									</div>
									<div class="water-level-data">
										<span class="blue">${name}</span>
										水位：
										<span class="blue">${level}</span> 米
										${warnImg}
									</div>
								</div>
								<div class="boxTail">
									<img src="${Static}img/aPicture/boxTail.png" />
								</div>`

				let overLayer = createdOverLayer(el, item.lng, item.lat)
				overLayerArr.push(overLayer)
			})

			return Promise.resolve({
				code: res.code,
				layer: layer,
				overLayerArr: overLayerArr
			})
		})
		.catch(res => {
			return Promise.resolve(res)
		})
}

// 潮位站 Layer
function tideGaugeLayer () {
	let url = `${globalConfig.mapIp}/bis/getsewagetreatment`

	return ajaxGet(url)
		.then(res => {
			let features = createHzzFeatures(res.result.result, `${Static}img/mapIcon/tideGaugeOpen.png`)
			let layer = createFeaturesLayer('tideGaugeLayer', features)

			return Promise.resolve({
				code: res.code,
				layer: layer
			})
		})
		.catch(res => {
			return Promise.resolve(res)
		})
}

// 建筑工地 Layer
function constructionSiteLayer () {
	let url = `${httpUrl}fullservice/http/building`

	return ajaxGet(url, {})
		.then(res => {
			let features = createFeatures('lng', 'lat', res.result, `${Static}img/mapIcon/constructionSite.png`)
			let layer = createFeaturesLayer('constructionSiteLayer', features)

			let overLayerArr = []
			res.result.map(item => {
				let name = item.constructionsite

				let el = createHtml('div')
				el.className = 'aPicture-map-infoOverLayer pad-10'
				el.innerHTML = `<div class="aPicture-map-infoOverLayer-warpper">
									<span class="blue">${name}</span>
								</div>
								<div class="boxTail">
									<img src="${Static}img/aPicture/boxTail.png" />
								</div>`

				let overLayer = createdOverLayer(el, item.lng, item.lat)
				overLayerArr.push(overLayer)
			})

			return Promise.resolve({
				code: res.code,
				layer: layer,
				overLayerArr: overLayerArr
			})
		})
		.catch(res => {
			return Promise.resolve(res)
		})
}

// 危险品
function dangerousGoodsLayer () {
	let url = `${httpUrl}fullservice/http/dangerousArticles`

	return ajaxGet(url, {})
		.then(res => {
			let features = createFeatures('lng', 'lat', res.result, `${Static}img/mapIcon/dangerousGoods.png`)
			let layer = createFeaturesLayer('dangerousGoodsLayer', features)

			let overLayerArr = []
			res.result.map(item => {
				let name = item.company_name

				let el = createHtml('div')
				el.className = 'aPicture-map-infoOverLayer pad-10'
				el.innerHTML = `<div class="aPicture-map-infoOverLayer-warpper">
									<span class="blue">${name}</span>
								</div>
								<div class="boxTail">
									<img src="${Static}img/aPicture/boxTail.png" />
								</div>`

				let overLayer = createdOverLayer(el, item.lng, item.lat)
				overLayerArr.push(overLayer)
			})

			return Promise.resolve({
				code: res.code,
				layer: layer,
				overLayerArr: overLayerArr
			})
		})
		.catch(res => {
			return Promise.resolve(res)
		})
}

/* 基础数据 */
// 广东水网 Layer
function GDwaterNetLayer () {
	return new ol.layer.Tile({
		source: new ol.source.TileArcGISRest({
			url: `${mapHttpUrl20462}arcgis/rest/services/data_visualization/foshan_waterbody_entire/MapServer`
		}),
		visible: false
	})
}

// 华南水网 Layer
function HNwaterNetLayer () {
	return new ol.layer.Tile({
		source: new ol.source.TileArcGISRest({
			url: `${mapHttpUrl20462}arcgis/rest/services/data_visualization/huanan_waterbody/MapServer`
		}),
		visible: false
	})
}

// 单条河涌 Layer
function singleWaterNetLayer () {
	return new ol.layer.Vector({
		source: new ol.source.Vector({}),
		style: function (feature, resolution) {
			return new ol.style.Style({
				stroke: new ol.style.Stroke({
					color: '#542036',
					width: 2
				}),
				fill: new ol.style.Fill({
					color: 'rgba(162, 206, 253, .6)'
				})
			})
		},
		name: 'singleWaterNetLayer',
		visible: false
	})
}

// 排水口 Layer
function drainPortLayer () {
	let url = `${httpUrl}fullservice/http/outfallInfo`

	return ajaxGet(url, {})
		.then(res => {
			let features = createFeatures('lng', 'lat', res.result, `${Static}img/mapIcon/drainPort.png`)
			let layer = createFeaturesLayer('drainPortLayer', features)

			let overLayerArr = []
			let hideClassName = 'mustHideOverLayers-15'
			res.result.map(item => {
				let name = item.pntplace

				let el = createHtml('div')
				el.className = `${hideClassName} aPicture-map-infoOverLayer pad-10`
				el.innerHTML = `<div class="aPicture-map-infoOverLayer-warpper">
									<span class="blue">${name}</span>
								</div>
								<div class="boxTail">
									<img src="${Static}img/aPicture/boxTail.png" />
								</div>`

				let overLayer = createdOverLayer(el, item.lng, item.lat)
				overLayerArr.push(overLayer)
			})

			return Promise.resolve({
				code: res.code,
				layer: layer,
				overLayerArr: overLayerArr,
				hideClassName: hideClassName
			})
		})
		.catch(res => {
			return Promise.resolve(res)
		})
}

// 构建筑物 Layer
function buildingLayer () {
	let url = `${globalConfig.mapIp}/bis/getdianpai`

	return ajaxGet(url, {})
		.then(res => {
			let features = createHzzFeatures(res.result.result, `${Static}img/mapIcon/building.png`)
			let layer = createFeaturesLayer('buildingLayer', features)

			return Promise.resolve({
				code: res.code,
				layer: layer
			})
		})
		.catch(res => {
			return Promise.resolve(res)
		})
}

// 堤围 Layer
function banksLayer () {
	let layer = createKMLLayer(`${Static}kml/banks/banks.kml`, 'banksLayer')

	return Promise.resolve({
		code: ERR_OK,
		layer: layer
	})
}

// 险段 Layer
function criticalsLayer () {
	let layer = createKMLLayer(`${Static}kml/criticals/criticals.kml`, 'criticalsLayer')

	return Promise.resolve({
		code: ERR_OK,
		layer: layer
	})
}

// 涵闸 layer
function waterGateLayer () {
	let url = `${httpUrl}fullservice/http/sluicegateInfo`

	return ajaxGet(url, {})
		.then(res => {
			let features = createFeatures('lng', 'lat', res.result, `${Static}img/mapIcon/waterGate.png`)
			let layer = createFeaturesLayer('waterGateLayer', features)

			let overLayerArr = []
			let hideClassName = 'mustHideOverLayers-12'
			res.result.map(item => {
				let name = item.sluicegate_name

				let el = createHtml('div')
				el.className = `${hideClassName} aPicture-map-infoOverLayer pad-10`
				el.innerHTML = `<div class="aPicture-map-infoOverLayer-warpper">
									<span class="blue">${name}</span>
								</div>
								<div class="boxTail">
									<img src="${Static}img/aPicture/boxTail.png" />
								</div>`

				let overLayer = createdOverLayer(el, item.lng, item.lat)
				overLayerArr.push(overLayer)
			})

			return Promise.resolve({
				code: res.code,
				layer: layer,
				overLayerArr: overLayerArr,
				hideClassName: hideClassName
			})
		})
		.catch(res => {
			return Promise.resolve(res)
		})
}

// 排灌站 Layer
function drainStationLayer () {
	let url = `${globalConfig.mapIp}/bis/gethydrology`

	return ajaxGet(url, {})
		.then(res => {
			let layer = createHzzLine(res.result.result, 'drainStationLayer', '#ADFF2F')
			console.log(layer)
			let hideClassName = 'mustHideOverLayers-12'
			return Promise.resolve({
				code: res.code,
				layer: layer,
				hideClassName: hideClassName
			})
		})
		.catch(res => {
			return Promise.resolve(res)
		})
}

// 水浸黑点 Layer
function blackPointLayer () {
	let url = `${httpUrl}fullservice/http/waterlogging2Info`

	return ajaxGet(url, {})
		.then(res => {
			let features = createFeatures('lng', 'lat', res.result, `${Static}img/mapIcon/blackPoint.png`)
			let layer = createFeaturesLayer('blackPointLayer', features)

			let overLayerArr = []
			let hideClassName = 'mustHideOverLayers-12'
			res.result.map(item => {
				let name = item.address

				let el = createHtml('div')
				el.className = `${hideClassName} aPicture-map-infoOverLayer pad-10`
				el.innerHTML = `<div class="aPicture-map-infoOverLayer-warpper">
									<span class="blue">${name}</span>
								</div>
								<div class="boxTail">
									<img src="${Static}img/aPicture/boxTail.png" />
								</div>`

				let overLayer = createdOverLayer(el, item.lng, item.lat)
				overLayerArr.push(overLayer)
			})

			return Promise.resolve({
				code: res.code,
				layer: layer,
				overLayerArr: overLayerArr,
				hideClassName: hideClassName
			})
		})
		.catch(res => {
			return Promise.resolve(res)
		})
}

// 下沉隧道 Layer
function sunkenTunnelLayer () {
	let url = `${httpUrl}fullservice/http/sunkenTunnel`

	return ajaxGet(url, {})
		.then(res => {
			let features = createFeatures('lng', 'lat', res.result, `${Static}img/mapIcon/sunkenTunnel.png`)
			let layer = createFeaturesLayer('sunkenTunnelLayer', features)

			let overLayerArr = []
			let hideClassName = 'mustHideOverLayers-12'
			res.result.map(item => {
				let name = item.tunnelname

				let el = createHtml('div')
				el.className = `${hideClassName} aPicture-map-infoOverLayer pad-10`
				el.innerHTML = `<div class="aPicture-map-infoOverLayer-warpper">
									<span class="blue">${name}</span>
								</div>
								<div class="boxTail">
									<img src="${Static}img/aPicture/boxTail.png" />
								</div>`

				let overLayer = createdOverLayer(el, item.lng, item.lat)
				overLayerArr.push(overLayer)
			})

			return Promise.resolve({
				code: res.code,
				layer: layer,
				overLayerArr: overLayerArr,
				hideClassName: hideClassName
			})
		})
		.catch(res => {
			return Promise.resolve(res)
		})
}

// 供水管网 Layer
function supplyPipeLayer () {
	let url = `${httpUrl}fullservice/http/waterSupplyPipeInfo`

	return ajaxGet(url, {})
		.then(res => {
			let arr = []
			res.result.map(item => {
				arr.push(createGeo('LineString', JSON.parse(item.path), item))
			})
			let geoJson = {
				features: arr,
				type: 'FeatureCollection'
			}
			let layer = new ol.layer.Vector({
				source: new ol.source.Vector({
					features: (new ol.format.GeoJSON()).readFeatures(geoJson, {
						dataProjection: 'EPSG:4326',
						featureProjection: 'EPSG:4326'
					})
				}),
				style: function (feature, resolution) {
					return new ol.style.Style({
						stroke: new ol.style.Stroke({
							color: '#ff0000',
							width: 3
						})
					})
				},
				name: 'supplyPipeLayer'
			})
			return Promise.resolve({
				code: res.code,
				layer: layer
			})
		})
		.catch(res => {
			return Promise.resolve(res)
		})
}

// 自来水厂 Layer
function waterFactoryLayer () {
	let url = `${httpUrl}fullservice/http/waterFactoryInfo`

	return ajaxGet(url, {})
		.then(res => {
			let features = createFeatures('lng', 'lat', res.result, `${Static}img/mapIcon/waterFactory.png`)
			let layer = createFeaturesLayer('waterFactoryLayer', features)

			let overLayerArr = []
			let hideClassName = 'mustHideOverLayers-12'
			res.result.map(item => {
				let name = item.factory_name

				let el = createHtml('div')
				el.className = `${hideClassName} aPicture-map-infoOverLayer pad-10`
				el.innerHTML = `<div class="aPicture-map-infoOverLayer-warpper">
									<span class="blue">${name}</span>
								</div>
								<div class="boxTail">
									<img src="${Static}img/aPicture/boxTail.png" />
								</div>`

				let overLayer = createdOverLayer(el, item.lng, item.lat)
				overLayerArr.push(overLayer)
			})

			return Promise.resolve({
				code: res.code,
				layer: layer,
				overLayerArr: overLayerArr,
				hideClassName: hideClassName
			})
		})
		.catch(res => {
			return Promise.resolve(res)
		})
}

// 供水设施 Layer
function supplyDeviceLayer () {
	let url = `${httpUrl}fullservice/http/waterSupplyFacilitiesInfo`

	return ajaxGet(url, {})
		.then(res => {
			let features = createFeatures('startlnt', 'startlat', res.result, `${Static}img/mapIcon/supplyDevice.png`)
			let layer = createFeaturesLayer('supplyDeviceLayer', features)

			let overLayerArr = []
			let hideClassName = 'mustHideOverLayers-12'
			res.result.map(item => {
				let name = item.pipe_line_name

				let el = createHtml('div')
				el.className = `${hideClassName} aPicture-map-infoOverLayer pad-10`
				el.innerHTML = `<div class="aPicture-map-infoOverLayer-warpper">
									<span class="blue">${name}</span>
								</div>
								<div class="boxTail">
									<img src="${Static}img/aPicture/boxTail.png" />
								</div>`

				let overLayer = createdOverLayer(el, item.startlnt, item.startlat)
				overLayerArr.push(overLayer)
			})

			return Promise.resolve({
				code: res.code,
				layer: layer,
				overLayerArr: overLayerArr,
				hideClassName: hideClassName
			})
		})
		.catch(res => {
			return Promise.resolve(res)
		})
}

// 排水管 Layer
function drainPipeLayer () {
	let url = `${httpUrl}fullservice/http/drainagePipeInfo`

	return ajaxGet(url, {})
		.then(res => {
			let arr = []
			res.result.map(item => {
				arr.push(createGeo('LineString', JSON.parse(item.path), item))
			})
			let geoJson = {
				features: arr,
				type: 'FeatureCollection'
			}
			let layer = new ol.layer.Vector({
				source: new ol.source.Vector({
					features: (new ol.format.GeoJSON()).readFeatures(geoJson, {
						dataProjection: 'EPSG:4326',
						featureProjection: 'EPSG:4326'
					})
				}),
				style: function (feature, resolution) {
					return new ol.style.Style({
						stroke: new ol.style.Stroke({
							color: '#7f00ff',
							width: 3
						})
					})
				},
				name: 'drainPipeLayer'
			})
			return Promise.resolve({
				code: res.code,
				layer: layer
			})
		})
		.catch(res => {
			return Promise.resolve(res)
		})
}

// 污水厂 Layer
function dirtyFactoryLayer () {
	let url = `${httpUrl}fullservice/http/wasterFactoryInfo`

	return ajaxGet(url, {})
		.then(res => {
			let features = createFeatures('lnt', 'lat', res.result, `${Static}img/mapIcon/dirtyFactory.png`)
			let layer = createFeaturesLayer('dirtyFactoryLayer', features)

			let overLayerArr = []
			let hideClassName = 'mustHideOverLayers-12'
			res.result.map(item => {
				let name = item.factory_name

				let el = createHtml('div')
				el.className = `${hideClassName} aPicture-map-infoOverLayer pad-10`
				el.innerHTML = `<div class="aPicture-map-infoOverLayer-warpper">
									<span class="blue">${name}</span>
								</div>
								<div class="boxTail">
									<img src="${Static}img/aPicture/boxTail.png" />
								</div>`

				let overLayer = createdOverLayer(el, item.lnt, item.lat)
				overLayerArr.push(overLayer)
			})

			return Promise.resolve({
				code: res.code,
				layer: layer,
				overLayerArr: overLayerArr,
				hideClassName: hideClassName
			})
		})
		.catch(res => {
			return Promise.resolve(res)
		})
}

// 排水设施 Layer
function drainDeviceLayer () {
	let url = `${httpUrl}fullservice/http/drainageFacilitiesInfo`

	return ajaxGet(url, {})
		.then(res => {
			let features = createFeatures('startlnt', 'startlat', res.result, `${Static}img/mapIcon/drainDevice.png`)
			let layer = createFeaturesLayer('drainDeviceLayer', features)

			let overLayerArr = []
			let hideClassName = 'mustHideOverLayers-12'
			res.result.map(item => {
				let name = item.pipe_line_name

				let el = createHtml('div')
				el.className = `${hideClassName} aPicture-map-infoOverLayer pad-10`
				el.innerHTML = `<div class="aPicture-map-infoOverLayer-warpper">
									<span class="blue">${name}</span>
								</div>
								<div class="boxTail">
									<img src="${Static}img/aPicture/boxTail.png" />
								</div>`

				let overLayer = createdOverLayer(el, item.startlnt, item.startlat)
				overLayerArr.push(overLayer)
			})

			return Promise.resolve({
				code: res.code,
				layer: layer,
				overLayerArr: overLayerArr,
				hideClassName: hideClassName
			})
		})
		.catch(res => {
			return Promise.resolve(res)
		})
}

// 村居 Layer
function rusticateLayer () {
	let url = `${httpUrl}fullservice/http/villageGridInfo`

	return ajaxGet(url, {})
		.then(res => {
			let features = createFeatures('longitude', 'latitude', res.result, `${Static}img/mapIcon/rusticate.png`)
			let layer = createFeaturesLayer('rusticateLayer', features)

			let overLayerArr = []
			let hideClassName = 'mustHideOverLayers-12'
			res.result.map(item => {
				let name = item.name

				let el = createHtml('div')
				el.className = `${hideClassName} aPicture-map-infoOverLayer pad-10`
				el.innerHTML = `<div class="aPicture-map-infoOverLayer-warpper">
									<span class="blue">${name}</span>
								</div>
								<div class="boxTail">
									<img src="${Static}img/aPicture/boxTail.png" />
								</div>`

				let overLayer = createdOverLayer(el, item.longitude, item.latitude)
				overLayerArr.push(overLayer)
			})

			return Promise.resolve({
				code: res.code,
				layer: layer,
				overLayerArr: overLayerArr,
				hideClassName: hideClassName
			})
		})
		.catch(res => {
			return Promise.resolve(res)
		})
}

// 路网 Layer
function roadNetLayer () {
	return new ol.layer.Tile({
		source: new ol.source.TileArcGISRest({
			url: `${mapHttpUrl20462}arcgis/rest/services/data_visualization/guangdong_road_normal/MapServer`
		})
	})
}

// 地质灾害 Layer
function hazardLayer () {
	let url = `${httpUrl}fullservice/http/geologicalDisasterInfo`

	return ajaxGet(url, {})
		.then(res => {
			let features = createFeatures('lng', 'lat', res.result, `${Static}img/mapIcon/hazard.png`)
			let layer = createFeaturesLayer('hazardLayer', features)

			let overLayerArr = []
			let hideClassName = 'mustHideOverLayers-12'
			res.result.map(item => {
				let name = item.code

				let el = createHtml('div')
				el.className = `${hideClassName} aPicture-map-infoOverLayer pad-10`
				el.innerHTML = `<div class="aPicture-map-infoOverLayer-warpper">
									<span class="blue">${name}</span>
								</div>
								<div class="boxTail">
									<img src="${Static}img/aPicture/boxTail.png" />
								</div>`

				let overLayer = createdOverLayer(el, item.lng, item.lat)
				overLayerArr.push(overLayer)
			})

			return Promise.resolve({
				code: res.code,
				layer: layer,
				overLayerArr: overLayerArr,
				hideClassName: hideClassName
			})
		})
		.catch(res => {
			return Promise.resolve(res)
		})
}

// 医院 Layer
function hospitalLayer () {
	let url = `${httpUrl}fullservice/http/majorPlaceInfo`

	return ajaxGet(url, {
			type: '医院'
		})
		.then(res => {
			let features = createFeatures('lng', 'lat', res.result, `${Static}img/mapIcon/hospital.png`)
			let layer = createFeaturesLayer('hospitalLayer', features)

			let overLayerArr = []
			let hideClassName = 'mustHideOverLayers-12'
			res.result.map(item => {
				let name = item.name

				let el = createHtml('div')
				el.className = `${hideClassName} aPicture-map-infoOverLayer pad-10`
				el.innerHTML = `<div class="aPicture-map-infoOverLayer-warpper">
									<span class="blue">${name}</span>
								</div>
								<div class="boxTail">
									<img src="${Static}img/aPicture/boxTail.png" />
								</div>`

				let overLayer = createdOverLayer(el, item.lng, item.lat)
				overLayerArr.push(overLayer)
			})

			return Promise.resolve({
				code: res.code,
				layer: layer,
				overLayerArr: overLayerArr,
				hideClassName: hideClassName
			})
		})
		.catch(res => {
			return Promise.resolve(res)
		})
}

// 学校 Layer
function schoolLayer () {
	let url = `${httpUrl}fullservice/http/majorPlaceInfo`

	return ajaxGet(url, {
			type: '学校'
		})
		.then(res => {
			let features = createFeatures('lng', 'lat', res.result, `${Static}img/mapIcon/school.png`)
			let layer = createFeaturesLayer('schoolLayer', features)

			let overLayerArr = []
			let hideClassName = 'mustHideOverLayers-12'
			res.result.map(item => {
				let name = item.name

				let el = createHtml('div')
				el.className = `${hideClassName} aPicture-map-infoOverLayer pad-10`
				el.innerHTML = `<div class="aPicture-map-infoOverLayer-warpper">
									<span class="blue">${name}</span>
								</div>
								<div class="boxTail">
									<img src="${Static}img/aPicture/boxTail.png" />
								</div>`

				let overLayer = createdOverLayer(el, item.lng, item.lat)
				overLayerArr.push(overLayer)
			})

			return Promise.resolve({
				code: res.code,
				layer: layer,
				overLayerArr: overLayerArr,
				hideClassName: hideClassName
			})
		})
		.catch(res => {
			return Promise.resolve(res)
		})
}

// 银行 Layer
function bankLayer () {
	let url = `${httpUrl}fullservice/http/majorPlaceInfo`

	return ajaxGet(url, {
			type: '银行'
		})
		.then(res => {
			let features = createFeatures('lng', 'lat', res.result, `${Static}img/mapIcon/bank.png`)
			let layer = createFeaturesLayer('bankLayer', features)

			let overLayerArr = []
			let hideClassName = 'mustHideOverLayers-12'
			res.result.map(item => {
				let name = item.name

				let el = createHtml('div')
				el.className = `${hideClassName} aPicture-map-infoOverLayer pad-10`
				el.innerHTML = `<div class="aPicture-map-infoOverLayer-warpper">
									<span class="blue">${name}</span>
								</div>
								<div class="boxTail">
									<img src="${Static}img/aPicture/boxTail.png" />
								</div>`

				let overLayer = createdOverLayer(el, item.lng, item.lat)
				overLayerArr.push(overLayer)
			})

			return Promise.resolve({
				code: res.code,
				layer: layer,
				overLayerArr: overLayerArr,
				hideClassName: hideClassName
			})
		})
		.catch(res => {
			return Promise.resolve(res)
		})
}

// 客运站 Layer
function busStationLayer () {
	let url = `${httpUrl}fullservice/http/majorPlaceInfo`

	return ajaxGet(url, {
			type: '客运站'
		})
		.then(res => {
			let features = createFeatures('lng', 'lat', res.result, `${Static}img/mapIcon/busStation.png`)
			let layer = createFeaturesLayer('busStationLayer', features)

			let overLayerArr = []
			let hideClassName = 'mustHideOverLayers-12'
			res.result.map(item => {
				let name = item.name

				let el = createHtml('div')
				el.className = `${hideClassName} aPicture-map-infoOverLayer pad-10`
				el.innerHTML = `<div class="aPicture-map-infoOverLayer-warpper">
									<span class="blue">${name}</span>
								</div>
								<div class="boxTail">
									<img src="${Static}img/aPicture/boxTail.png" />
								</div>`

				let overLayer = createdOverLayer(el, item.lng, item.lat)
				overLayerArr.push(overLayer)
			})

			return Promise.resolve({
				code: res.code,
				layer: layer,
				overLayerArr: overLayerArr,
				hideClassName: hideClassName
			})
		})
		.catch(res => {
			return Promise.resolve(res)
		})
}

// 商场 Layer
function shopLayer () {
	let url = `${httpUrl}fullservice/http/majorPlaceInfo`

	return ajaxGet(url, {
			type: '商场'
		})
		.then(res => {
			let features = createFeatures('lng', 'lat', res.result, `${Static}img/mapIcon/shop.png`)
			let layer = createFeaturesLayer('shopLayer', features)

			let overLayerArr = []
			let hideClassName = 'mustHideOverLayers-12'
			res.result.map(item => {
				let name = item.name

				let el = createHtml('div')
				el.className = `${hideClassName} aPicture-map-infoOverLayer pad-10`
				el.innerHTML = `<div class="aPicture-map-infoOverLayer-warpper">
									<span class="blue">${name}</span>
								</div>
								<div class="boxTail">
									<img src="${Static}img/aPicture/boxTail.png" />
								</div>`

				let overLayer = createdOverLayer(el, item.lng, item.lat)
				overLayerArr.push(overLayer)
			})

			return Promise.resolve({
				code: res.code,
				layer: layer,
				overLayerArr: overLayerArr,
				hideClassName: hideClassName
			})
		})
		.catch(res => {
			return Promise.resolve(res)
		})
}

// 三防数据

// 抢险队 Layer
function emergencySquadLayer () {
	let url = `${httpUrl}fullservice/http/emergencySquad`

	return ajaxGet(url, {})
		.then(res => {
			let features = createFeatures('lng', 'lat', res.result, `${Static}img/mapIcon/emergencySquad.png`)
			let layer = createFeaturesLayer('emergencySquadLayer', features)

			let overLayerArr = []
			res.result.map(item => {
				let name = item.name

				let el = createHtml('div')
				el.className = `aPicture-map-infoOverLayer pad-10`
				el.innerHTML = `<div class="aPicture-map-infoOverLayer-warpper">
									<span class="blue">${name}</span>
								</div>
								<div class="boxTail">
									<img src="${Static}img/aPicture/boxTail.png" />
								</div>`

				let overLayer = createdOverLayer(el, item.lng, item.lat)
				overLayerArr.push(overLayer)
			})

			return Promise.resolve({
				code: res.code,
				layer: layer,
				overLayerArr: overLayerArr
			})
		})
		.catch(res => {
			return Promise.resolve(res)
		})
}

// 救援队 Layer
function rescueTeamLayer () {
	let url = `${httpUrl}fullservice/http/rescueTeam`

	return ajaxGet(url, {})
		.then(res => {
			let features = createFeatures('lng', 'lat', res.result, `${Static}img/mapIcon/rescueTeam.png`)
			let layer = createFeaturesLayer('rescueTeamLayer', features)

			let overLayerArr = []
			res.result.map(item => {
				let name = item.name

				let el = createHtml('div')
				el.className = `aPicture-map-infoOverLayer pad-10`
				el.innerHTML = `<div class="aPicture-map-infoOverLayer-warpper">
									<span class="blue">${name}</span>
								</div>
								<div class="boxTail">
									<img src="${Static}img/aPicture/boxTail.png" />
								</div>`

				let overLayer = createdOverLayer(el, item.lng, item.lat)
				overLayerArr.push(overLayer)
			})

			return Promise.resolve({
				code: res.code,
				layer: layer,
				overLayerArr: overLayerArr
			})
		})
		.catch(res => {
			return Promise.resolve(res)
		})
}

// 群众热力分布 Layer
function massHeatLayer () {
	let url = `${httpUrl}fullservice/http/peopleHeadHot`

	return ajaxGet(url, {})
		.then(res => {
			let layer = new ol.layer.Heatmap({
				source: createdKmlSource(),
				blur: 30,
				radius: 50,
				gradient: ['#5a00ff', '#00e4ff', '#00ff00', '#ffff00', '#ff0000']
			})

			layer.on('change:source', function (event) {
				event.target.get('source').getFeatures().map(item => {
					let name = item.get('name')
					item.set('weight', name / 30000)
				})
			})

			layer.setSource(createdKmlSource(res.result[0].kml))

			return Promise.resolve({
				code: res.code,
				layer: layer,
				result: res.result
			})
		})
		.catch(res => {
			return Promise.resolve(res)
		})
}

// 重点人员实时位置 Layer
function liabilityPersonLayer () {
	let url = `${httpUrl}fullservice/http/liabilityPerson`

	return ajaxGet(url, {})
		.then(res => {
			let features = createFeatures('lng', 'lat', res.result, `${Static}img/mapIcon/liabilityPerson.png`)
			let layer = createFeaturesLayer('liabilityPersonLayer', features)

			let overLayerArr = []
			res.result.map(item => {
				let name = item.name

				let el = createHtml('div')
				el.className = `aPicture-map-infoOverLayer pad-10`
				el.innerHTML = `<div class="aPicture-map-infoOverLayer-warpper">
									<span class="blue">${name}</span>
								</div>
								<div class="boxTail">
									<img src="${Static}img/aPicture/boxTail.png" />
								</div>`

				let overLayer = createdOverLayer(el, item.lng, item.lat)
				overLayerArr.push(overLayer)
			})

			return Promise.resolve({
				code: res.code,
				layer: layer,
				overLayerArr: overLayerArr
			})
		})
		.catch(res => {
			return Promise.resolve(res)
		})
}

// 三防专家实时位置 Layer
function defenseExpertLayer () {
	let url = `${httpUrl}fullservice/http/defenseExpert`

	return ajaxGet(url, {})
		.then(res => {
			let features = createFeatures('lng', 'lat', res.result, `${Static}img/mapIcon/defenseExpert.png`)
			let layer = createFeaturesLayer('defenseExpertLayer', features)

			let overLayerArr = []
			res.result.map(item => {
				let name = item.name

				let el = createHtml('div')
				el.className = `aPicture-map-infoOverLayer pad-10`
				el.innerHTML = `<div class="aPicture-map-infoOverLayer-warpper">
									<span class="blue">${name}</span>
								</div>
								<div class="boxTail">
									<img src="${Static}img/aPicture/boxTail.png" />
								</div>`

				let overLayer = createdOverLayer(el, item.lng, item.lat)
				overLayerArr.push(overLayer)
			})

			return Promise.resolve({
				code: res.code,
				layer: layer,
				overLayerArr: overLayerArr
			})
		})
		.catch(res => {
			return Promise.resolve(res)
		})
}

// 避难所 Layer
function refugeLayer () {
	let url = `${httpUrl}fullservice/http/refugeInfo`

	return ajaxGet(url, {})
		.then(res => {
			let features = createFeatures('longitude', 'latitude', res.result, `${Static}img/mapIcon/refuge.png`)
			let layer = createFeaturesLayer('refugeLayer', features)

			let overLayerArr = []
			let hideClassName = 'mustHideOverLayers-12'
			res.result.map(item => {
				let name = item.name

				let el = createHtml('div')
				el.className = `${hideClassName} aPicture-map-infoOverLayer pad-10`
				el.innerHTML = `<div class="aPicture-map-infoOverLayer-warpper">
									<span class="blue">${name}</span>
								</div>
								<div class="boxTail">
									<img src="${Static}img/aPicture/boxTail.png" />
								</div>`

				let overLayer = createdOverLayer(el, item.longitude, item.latitude)
				overLayerArr.push(overLayer)
			})

			return Promise.resolve({
				code: res.code,
				layer: layer,
				overLayerArr: overLayerArr,
				hideClassName: hideClassName
			})
		})
		.catch(res => {
			return Promise.resolve(res)
		})
}

// 物资仓库 Layer
function emergencyLayer () {
	let url = `${httpUrl}fullservice/http/suppliesWarehouseInfo`

	return ajaxGet(url, {})
		.then(res => {
			let features = createFeatures('lng', 'lat', res.result, `${Static}img/mapIcon/emergency.png`)
			let layer = createFeaturesLayer('emergencyLayer', features)

			let overLayerArr = []
			let hideClassName = 'mustHideOverLayers-12'
			res.result.map(item => {
				let name = item.name

				let el = createHtml('div')
				el.className = `${hideClassName} aPicture-map-infoOverLayer pad-10`
				el.innerHTML = `<div class="aPicture-map-infoOverLayer-warpper">
									<span class="blue">${name}</span>
								</div>
								<div class="boxTail">
									<img src="${Static}img/aPicture/boxTail.png" />
								</div>`

				let overLayer = createdOverLayer(el, item.lng, item.lat)
				overLayerArr.push(overLayer)
			})

			return Promise.resolve({
				code: res.code,
				layer: layer,
				overLayerArr: overLayerArr,
				hideClassName: hideClassName
			})
		})
		.catch(res => {
			return Promise.resolve(res)
		})
}

// 气象实况视频 Layer
function weatherVideoLayer () {
	let url = `${httpUrl}fullservice/http/watchVideo`

	return ajaxGet(url, {
			type: '气象实况'
		})
		.then(res => {
			let features = createFeatures('lng', 'lat', res.result, `${Static}img/mapIcon/waterProjectVideo.png`)
			let layer = createFeaturesLayer('weatherVideoLayer', features)
			return Promise.resolve({
				code: res.code,
				layer: layer
			})
		})
		.catch(res => {
			return Promise.resolve(res)
		})
}

// 治安监控视频 Layer
function policVideoLayer () {
	let url = `${httpUrl}fullservice/http/watchVideo`

	return ajaxGet(url, {
			type: '治安监控'
		})
		.then(res => {
			let features = createFeatures('lng', 'lat', res.result, `${Static}img/mapIcon/waterProjectVideo.png`)
			let layer = createFeaturesLayer('policVideoLayer', features)
			return Promise.resolve({
				code: res.code,
				layer: layer
			})
		})
		.catch(res => {
			return Promise.resolve(res)
		})
}

// 西江视频 Layer
function westRiverVideoLayer () {
	let url = `${httpUrl}fullservice/http/watchVideo`

	return ajaxGet(url, {
			type: '西江'
		})
		.then(res => {
			let features = createFeatures('lng', 'lat', res.result, `${Static}img/mapIcon/waterProjectVideo.png`)
			let layer = createFeaturesLayer('westRiverVideoLayer', features)
			return Promise.resolve({
				code: res.code,
				layer: layer
			})
		})
		.catch(res => {
			return Promise.resolve(res)
		})
}

// 污染源视频 Layer
function pollutionVideoLayer () {
	let url = `${httpUrl}fullservice/http/watchVideo`

	return ajaxGet(url, {
			type: '污染源'
		})
		.then(res => {
			let features = createFeatures('lng', 'lat', res.result, `${Static}img/mapIcon/waterProjectVideo.png`)
			let layer = createFeaturesLayer('pollutionVideoLayer', features)
			return Promise.resolve({
				code: res.code,
				layer: layer
			})
		})
		.catch(res => {
			return Promise.resolve(res)
		})
}

// 水利工程视频 Layer
function waterProjectVideoLayer () {
	let url = `${httpUrl}fullservice/http/watchVideo`

	return ajaxGet(url, {
			type: '水利工程'
		})
		.then(res => {
			let features = createFeatures('lng', 'lat', res.result, `${Static}img/mapIcon/waterProjectVideo.png`)
			let layer = createFeaturesLayer('waterProjectVideoLayer', features)

			let overLayerArr = []
			let hideClassName = 'mustHideOverLayers-12'
			res.result.map(item => {
				let name = item.video_title

				let el = createHtml('div')
				el.className = `${hideClassName} aPicture-map-infoOverLayer pad-10`
				el.innerHTML = `<div class="aPicture-map-infoOverLayer-warpper">
									<span class="blue">${name}</span>
								</div>
								<div class="boxTail">
									<img src="${Static}img/aPicture/boxTail.png" />
								</div>`

				let overLayer = createdOverLayer(el, item.lng, item.lat)
				overLayerArr.push(overLayer)
			})

			return Promise.resolve({
				code: res.code,
				layer: layer,
				overLayerArr: overLayerArr,
				hideClassName: hideClassName
			})
		})
		.catch(res => {
			return Promise.resolve(res)
		})
}

// 避难所视频 Layer
function refugeVideoLayer () {
	let url = `${httpUrl}fullservice/http/watchVideo`

	return ajaxGet(url, {
			type: '避难所'
		})
		.then(res => {
			let features = createFeatures('lng', 'lat', res.result, `${Static}img/mapIcon/waterProjectVideo.png`)
			let layer = createFeaturesLayer('refugeVideoLayer', features)
			return Promise.resolve({
				code: res.code,
				layer: layer
			})
		})
		.catch(res => {
			return Promise.resolve(res)
		})
}

// 空间查询 画图工具 Layer
function searchSpaceDrawLayer () {
	return new ol.layer.Vector({
		source: new ol.source.Vector(),
		style: [new ol.style.Style({
			stroke: new ol.style.Stroke({
				color: '#008cee',
				width: 2
			}),
			fill: new ol.style.Fill({
				color: 'rgba(255,255,255,0.5)'
			})
		})],
		name: 'searchSpaceDrawLayer',
		zIndex: 100
	})
}

// 搜索结果和空间查询点击列表数据 Layer
function searchClickLayer () {
	let el = createHtml('div')

	el.className = `searchClick-overLayer aPicture-map-infoOverLayer pad-10`
	el.innerHTML = `<div class="aPicture-map-infoOverLayer-warpper blue"></div>
					<div class="boxTail">
						<img src="${Static}img/aPicture/boxTail.png" />
					</div>`

	let overLayer = createdOverLayer(el, 113.0445, 23.0907)

	return overLayer
}

// 搜索建筑结果 Layer
function searchBuildLayer (str) {
	let url = `${httpUrl}fullservice/http/searchInfo`

	let data = {
		q: str
	}

	return ajaxGet(url, data)
		.then(res => {
			let obj = {}
			let result = []

			if (res.result.length) {
				obj = createSearchBuildLayer(res.result)
				result = res.result
			}

			result.map(item => {
				item.CUSTOM_TYPE = 'icons'
			})

			return Promise.resolve({
				code: res.code,
				result,
				...obj
			})
		})
		.catch(res => {
			return Promise.resolve(res)
		})
}

// 搜索 河涌结果 Layer
function searchRiverLayer (str) {
	let url = `${mapHttpUrl20462}arcgis/rest/services/data_visualization/guangdong_waterbody_entire/MapServer/find`
	let data = {
		searchText: str,
		contains: 'true',
		searchFields: 'name',
		sr: '',
		layers: 0,
		layerDefs: '',
		returnGeometry: 'true',
		maxAllowableOffset: '',
		geometryPrecision: '',
		dynamicLayers: '',
		returnZ: 'false',
		returnM: 'false',
		gdbVersion: '',
		f: 'pjson',
		t: new Date().getTime()
	}
	return ajaxGet(url, data)
		.then(res => {
			let code, layer
			let obj = {}
			let result = []

			if (res.results) {
				code = ERR_OK

				res.results.map(item => {
					result.push({
						CUSTOM_TYPE: 'rivers',
						name: item.attributes.name,
						type: 'waterNet',
						data: item
					})
				})

				layer = new ol.layer.Vector({
					source: createSearchRiverSource(res.results[0]).source,
					style: function (feature, resolution) {
						return new ol.style.Style({
							stroke: new ol.style.Stroke({
								color: '#542036',
								width: 2
							}),
							fill: new ol.style.Fill({
								color: 'rgba(162, 206, 253, .6)'
							})
						})
					},
					name: 'searchRiverLayer'
				})
			}

			return Promise.resolve({
				code: code,
				result,
				layer
			})
		})
		.catch(res => {
			return Promise.resolve(res)
		})
}

// 空间查询 Layer
function searchSpaceLayer (center, local) {
	let url = `${httpUrl}fullservice/http/drawMapSearch`

	let data = {
		lat: center[1],
		lng: center[0],
		distance: local
	}

	return ajaxGet(url, data)
		.then(res => {
			let obj = {}
			let result = {}

			if (res.result) {
				obj = createSearchBuildLayer(res.result.data)
				result = res.result
			}

			result.data.map(item => {
				item.CUSTOM_TYPE = 'icons'
			})

			return Promise.resolve({
				code: res.code,
				result,
				...obj,
				typeLayer: searchSpaceTypeLayer(res.result.total)
			})
		})
		.catch(res => {
			return Promise.resolve(res)
		})
}

// 空间查询 分类 统计框
function searchSpaceTypeLayer (obj) {
	let el = createHtml('div')

	let str = ''

	for (let key in obj) {
		if (obj[key].type) {
			str += `<div class="pull-left searchSpaceType-detail">
						<img src="${Static}img/mapIcon/${obj[key].type}.png" width="20" />
						<span>${key}: </span><span class="blue">${obj[key].count}</span><span>个</span>
					</div>`
		}
	}

	el.className = `searchSpaceType-overLayer aPicture-map-infoOverLayer pad-5`
	el.innerHTML = `<div class="aPicture-map-infoOverLayer-warpper clear">${str}</div>
					<div class="boxTail">
						<img src="${Static}img/aPicture/boxTail.png" />
					</div>`

	let overLayer = createdOverLayer(el, 113.0445, 23.0907, [0, 5])

	return overLayer
}

// 创建搜索 建筑结果和空间查询 Layer
function createSearchBuildLayer (data) {
	let obj = {}
	let feature = {}
	let features = []
	let overLayerArr = []

	data.map((item, index) => {
		if (obj[item.type] === undefined) {
			obj[item.type] = []
		}
		obj[item.type].push(item)

		let el = createHtml('div')
		el.className = `search-overLayer search-overLayer${index} aPicture-map-infoOverLayer pad-10`
		el.innerHTML = `<div class="aPicture-map-infoOverLayer-warpper blue">
							${item.name}
						</div>
						<div class="boxTail">
							<img src="${Static}img/aPicture/boxTail.png" />
						</div>`

		let overLayer = createdOverLayer(el, item.lng, item.lat)
		overLayerArr.push(overLayer)
	})

	for (let key in obj) {
		feature[key] = createFeatures('lng', 'lat', obj[key], `${Static}img/mapIcon/${key}.png`)
	}

	for (let key in feature) {
		feature[key].map(item => {
			features.push(item)
		})
	}

	let layer = createFeaturesLayer('searchLayer', features, 101)

	return {
		layer,
		overLayerArr
	}
}

// 创建搜索 河涌结果和空间查询 Layer
export function createSearchRiverSource (data) {
	let rings = data.geometry.rings

	// 高亮显示这条河
	let geoJson = {
		type: 'Polygon',
		coordinates: rings
	}

	let source = new ol.source.Vector({
		features: (new ol.format.GeoJSON()).readFeatures(geoJson, {
			dataProjection: 'EPSG:4326',
			// 设定JSON数据使用的坐标系

			featureProjection: 'EPSG:4326'
			// 设定当前地图使用的feature的坐标系
		})
	})

	return {
		source
	}
}
